// pages/favor/favor.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNumber: 1,
    item: '',
    list: [],
    type: 1,
    totype: 1,
    typeShow: false,
    totalPages: 1,
    login: false,
    phone: false,
    loginShow: false,
    phoneshow: false,
  },
  login() {
    if (this.data.login) {
      this.toggle('phoneshow', true)
      this.selectComponent('#phone').showClose()
    } else {
      this.toggle('loginShow', true)
      this.selectComponent('#login').showClose()
    }
  },
  toggleToast(e) {
    console.log(e.detail)
    if (!e.detail.loginShow) {
      this.toggle('loginShow', false)
    }
    this.onShow()
  },
  toggleToast1(e) {
    console.log(e.detail)
    if (!e.detail.phoneshow) {
      this.toggle('phoneshow', false)
    }
    this.onShow()
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  topage(e) {
    var type = e.currentTarget.dataset.type
    if (type == 7) {
      wx.navigateTo({
        url: '/pages/blessingDetailed/blessingDetailed',
      })
    } else {
      wx.navigateTo({
        url: '/pages/redEnvelopes/redEnvelopes?type=' + type,
      })
    }
  },
  topersonal(e) {
    var detg = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/personal/personal?id=' + detg.id + "&name=" + detg.name + '&num=' + detg.num + '&url=' + detg.url,
    })
  },
  typeshow() {
    this.setData({
      typeShow: true
    })
  },
  single(e) {
    var type = e.currentTarget.dataset.type
    this.setData({
      type: type
    })
  },
  cel() {
    this.setData({
      type: this.data.totype,
      typeShow: false,
    })
  },
  confirm() {
    this.setData({
      totype: this.data.type,
      typeShow: false,
      list: [],
      pageNumber: 1,
    })
    this.getdetails(this.data.type)
  },
  getdetails(e) {
    var that = this
    app.req({
      url: "blessmini/rank/statistics",
      data: {
        pageNumber: that.data.pageNumber,
        pageSize: 10,
        type: parseInt(e),
      },
      method: "post",
      success: function (res) {
        if (res.code == 200) {
          that.setData({
            item: res.data,
            list: that.data.list.concat(res.data.ranks.rows),
            totalPages: res.data.ranks.totalPages
          })
          console.log('人情账', that.data.item)
        }
      }
    })
  },
  preventTouchMove: function (e) {
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
      list: [],
      pageNumber: 1,
    })
    if (wx.getStorageSync('uid') == '') {
      that.toggle("login", false);
      console.log('隐藏2', that.data.phoneshow)
    } else {
      that.toggle("login", true);
      console.log('隐藏3', that.data.phoneshow)
      var phone = wx.getStorageSync("phone")
      if (phone == '') {
        that.toggle("phone", true);
      } else {
        that.toggle("phone", false);
        that.toggle("phoneshow", false);
        that.toggle("loginShow", false);
        console.log('隐藏4', that.data.phoneshow)
        app.getUserInfo(function (userInfo) {
          that.toggle("userInfo", userInfo);
        })
      }
    }
    that.getdetails(that.data.type)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if (that.data.totalPages > that.data.pageNumber) {
      that.setData({
        pageNumber: that.data.pageNumber + 1
      })
      that.getdetails(that.data.type)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})